import React, { Component, Suspense } from 'react';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';

import { connect } from 'dva';
import PageLoading from '@/components/PageLoading';
import { FormattedMessage } from 'umi-plugin-react/locale';
import {
  Row,
  Col,
  Card,
  Icon,
  Form,
  Button,
  Input,
  Spin,
  Table,
  Modal,
  Radio,
  Pagination,
  message,
  Drawer,
  Tooltip,
} from 'antd';
import { columnsTable } from './wordData';
import styles from './index.less';
import Service from '../../../modules/service';
import deleteimg from '@/assets/buttonimg/delete.png';
import RobotBtn from '@/utils/robotBtn';

const FormItem = Form.Item;
const Search = Input.Search;
const RadioGroup = Radio.Group;
const MyIcon = Icon.createFromIconfontCN({
  scriptUrl: '//at.alicdn.com/t/font_1131883_m18hmgbwet.js', // 在 iconfont.cn 上生成
});
import ljx from '../../../assets/icons/垃圾箱.png';
import pen from '../../../assets/icons/bi.png';
import newcicao from '@/assets/basic/customDictionary/newcicao.png';
import moreImg from '@/assets/knowledge/more.png';
import Bottword from '@/modules/Bottword.js';
import moveImg from '@/assets/knowledge/move.png';
import sy from '@/assets/basic/customDictionary/sy.png';
import bianji from '@/assets/basic/customDictionary/bianji.png';
import edit from '@/assets/basic/customDictionary/edit.png';
import qdbuttom from '@/assets/account/robotSetup/qdbuttom.png';
import qxbuttom from '@/assets/account/robotSetup/qxbuttom.png';

class WordTroughManage extends Component {
  constructor(props) {
    super(props);
    this.state = {
      total: 0,
      login: false,
      dataSource1: [],
      pageSizeA: 10,
      pageA: 1,
      pageSize: 10,
      page: 1,
      pageC: 1,
      pageSizeC: 10,
      addModel: false,
      wordName: '',
      wordAlias: '',
      visitWords: '',
      showModel: false,
      value: 'none',
      onChantTable: 1,
      item: {},
      choice: [{ choiceType: 'user', customs: [], plug: 'tcx' }],
      personalityList: [],
      personalitytotal: '',
      editor: true,
      textOne: '',
      slotId: '',
      yeshua: 1,
      yeshub: 10,
      zhuvalue: '',
      close: false,
      dictType: 'user',
      inputT: '',
      isEnum: true,
      isEnumTwo: null,
    };

    this.bardian = [
      {
        title: '列表',
        width: 'calc(80vw)',
        dataIndex: 'name',
      },
      {
        title: '操作',
        width: 'calc(20vw)',
        render: (text, item) => (
          <span>
            <Button
              onClick={text => {
                this.handleDeleteA(item);
              }}
              type="primary"
              size="small"
            >
              选择
            </Button>
          </span>
        ),
      },
    ];
  }

  inSue = item => {
    let a = item;
    a.id = item._id;
    console.log(a);
    this.setState({ item: a }, () => {
      this.openClose();
    });
  };

  openClose = () => {
    this.setState({ close: true });
  };

  onClose = () => {
    this.setState({
      close: false,
    });
  };

  // eslint-disable-next-line react/sort-comp
  handleDelete = a => {
    // console.log(a)
    const { dispatch } = this.props;
    this.reqRef = requestAnimationFrame(() => {
      dispatch({
        type: 'wordTroughManage/fetchf',
        payload: { id: a._id },
        callback: res => {
          console.log(res);
          this.setState({ isEnum: res.firstDictEnum, isEnumTwo: res.firstDictEnum ? true : false });
          if (res.choice.customs.length === 0) {
            this.setState({
              value: 'none',
              choice: [{ choiceType: 'user', customs: [], plug: 'tcx' }],
              addModel: true,
              wordName: res.key,
              wordAlias: res.name,
              visitWords: res.inquire,
              textOne: res.firstDictName,
              textId: res.firstDictId,
              editor: false,
              slotId: res._id,
            });
          } else {
            let customslist = res.choice.customs;
            if (customslist.length !== 0) {
              this.setState({ value: 'user' });
            }
            let a = [];
            let customs = [];
            customslist.map((item, index) => {
              let maplist = { choiceType: 'user', customs: [], plug: 'tcx' };
              maplist.customs = [];
              maplist.customs.push(item);
              a.push(maplist);
            });
            for (let i = 0; i < a.length - 1; i++) {
              a[i].plug = '';
            }
            this.setState({ choice: a });
            console.log('编辑词槽数据', res, a);
            this.setState({
              addModel: true,
              wordName: res.key,
              wordAlias: res.name,
              visitWords: res.inquire,
              textOne: res.firstDictName,
              textId: res.firstDictId,
              editor: false,
              slotId: res._id,
            });
          }
        },
      });
    });
  };

  fetch = (page = 1, limit = 10, keys) => {
    this.setState({
      login: true,
    });
    const { dispatch, currentUser } = this.props;
    this.reqRef = requestAnimationFrame(() => {
      dispatch({
        type: 'wordTroughManage/fetch',
        payload: { robotId: currentUser.robotId, page, limit, keys },
        callback: res => {
          console.log('列表数据', res);
          let temp = res.list;
          temp.map((item, index) => {
            item.nameTwo = item.key;
            item.key = index;
          });
          // temp.reverse()
          this.setState({
            dataSource1: temp,
            total: Number(res.total),
            login: false,
          });
        },
      });
    });
  };

  fetchd = (dictType, page, limit, dictNames) => {
    this.setState({
      login: true,
    });
    const { dispatch, currentUser } = this.props;
    this.reqRef = requestAnimationFrame(() => {
      dispatch({
        type: 'wordTroughManage/basicDictSysList',
        payload: { query: this.state.inputT },
        callback: res => {
          console.log('个性化词典列表', res);
          let temp = res;
          this.setState({ personalityList: temp, login: false });
        },
      });
    });
  };

  // 自定义实体
  fetche = () => {
    this.setState({
      login: true,
    });
    const { dispatch, currentUser } = this.props;
    this.reqRef = requestAnimationFrame(() => {
      dispatch({
        type: 'wordTroughManage/basicDictList',
        payload: { page: this.state.pageC, limit: this.state.pageSizeC, query: this.state.inputT },
        callback: res => {
          console.log('个性化词典列表', res);
          res.data.list.map((item, index) => {
            item['key'] = index;
          });
          this.setState({
            personalityList: res.data.list,
            personalitytotalC: Number(res.data.total),
            login: false,
          });
        },
      });
    });
  };

  handleDeleteA = text => {
    // 获取数据
    console.log(text);
    this.setState({
      showModel: false,
      textOne: text.name,
      textId: text.id,
      editor: false,
      isEnum: text.isEnum,
    });
  };

  componentDidMount() {
    this.fetch();
  }

  onChangeB = e => {
    console.log(e);
    this.setState({ yeshua: e }, () => {
      this.fetch(this.state.yeshua, this.state.yeshub, this.state.zhuvalue);
    });
  };

  onShowSizeChangeB = (va, vb) => {
    console.log(va, vb);
    this.setState({ yeshub: vb, yeshua: va }, () => {
      this.fetch(this.state.yeshua, this.state.yeshub, this.state.zhuvalue);
    });
    // this.fetch(va, vb, '')
  };

  beginFrom = () => {
    this.props.form.setFields({ wordName: '' });
    this.props.form.setFields({ wordAlias: '' });
    this.props.form.setFields({ visitWords: '' });

    this.setState({
      textId: '',
    });
  };

  onClosebj = () => {
    this.setState({
      addModel: false,
      editor: true,
      onChantTable: 1,
    });
    this.beginFrom();
  };

  render() {
    // console.log(this.state.dataSource1)
    const operationDate = [
      {
        title: <FormattedMessage id="app.wordTroughManage.word-name" />,
        dataIndex: 'nameTwo',
        align: 'left',
        width: 'calc(18vw)',
      },
      {
        title: <FormattedMessage id="app.wordTroughManage.word-alias" />,
        dataIndex: 'name',
        align: 'center',
        width: 'calc(18vw)',
      },
      {
        title: <FormattedMessage id="app.wordTroughManage.dictionary" />,
        dataIndex: 'dictName',
        align: 'center',
        width: 'calc(18vw)',
      },
      {
        title: <FormattedMessage id="app.wordTroughManage.collect" />,
        dataIndex: 'isRequired',
        width: 'calc(10vw)',
        align: 'center',
        render(sex) {
          return sex === true ? 'true' : 'false';
        },
      },
      {
        title: <FormattedMessage id="app.wordTroughManage.operation" />,
        width: '250px',
        align: 'center',
        render: (text, item) => {
          return (
            <div className={styles.pb}>
              <div className={styles.tool}>
                {item.inUse ? (
                  <img
                    onClick={text => {
                      this.inSue(item);
                    }}
                    src={sy}
                  />
                ) : (
                  <span>&#12288;&#12288;&#12288;&#12288;&#12288;</span>
                )}
                <img
                  onClick={text => {
                    this.handleDelete(item);
                  }}
                  src={bianji}
                />
                <img
                  onClick={text => {
                    this.handleDeletes(item);
                  }}
                  style={{ marginLeft: 15 }}
                  src={edit}
                />
              </div>
              <img src={moreImg} className={styles.more} />
            </div>
          );
        },
      },
    ];
    const { getFieldDecorator } = this.props.form;
    // const FormItemLayont = { labelCol: { xs: 24, sm: 5 }, wrapperCol: { xs: 24, sm: 19 } };
    const FormItemLayont = {
      labelCol: {
        // 文字
        xs: 24,
        sm: 4,
        md: 2,
      },
      wrapperCol: {
        // 输入框
        xs: 24,
        sm: 20,
        md: 20,
      },
    };
    return (
      <div style={{ margin: '0px 0px' }}>
        <div className={styles.backgroundp}>
          {/* <Card> */}
          {/* <Card bordered={false}> */}
          <p style={{ marginLeft: 20, marginTop: 10 }} className="titleA">
            词槽管理
          </p>
          <div style={{ marginLeft: 12, marginRight: 25 }} className="zdyinputa">
            {/* <Button type="primary" icon="plus" htmlType="button" onClick={() => this.newWordTrough()}>
                  <FormattedMessage id="app.wordTroughManage.add" />
                </Button> */}
            <img
              style={{ position: 'relative', top: 8, cursor: 'pointer' }}
              onClick={() => this.newWordTrough()}
              src={newcicao}
            />
            <Search
              className={styles.float}
              placeholder="请输入搜索内容"
              onSearch={value => {
                this.setState({ yeshua: 1, zhuvalue: value }, () => {
                  this.fetch(this.state.yeshua, this.state.yeshub, value);
                });
              }}
              style={{ height: 50, width: 312 }}
            />
          </div>
          <div style={{ marginTop: 20 }}>
            <Spin spinning={this.state.login}>
              <div className={styles.dabj} style={{ padding: '0px 20px' }}>
                <div className={styles.border} style={{ position: 'relative', right: '2px' }}>
                  <Table
                    className="zdyTable"
                    columns={operationDate}
                    dataSource={this.state.dataSource1} //数据
                    pagination={false}
                  />
                </div>
              </div>
              <Pagination
                style={{ textAlign: 'center', marginTop: 20 }}
                total={this.state.total}
                pageSize={this.state.yeshub} // 显示几条一页
                current={this.state.yeshua} // 当前页
                showSizeChanger={true} // 是否显示可以设置几条一页的选项
                onChange={this.onChangeB}
                onShowSizeChange={this.onShowSizeChangeB}
                showTotal={() => `共 ${this.state.total} 条`}
              />
            </Spin>
          </div>
          {/* </Card> */}
          <Drawer
            className="zdyset"
            title={
              <span  onClick={this.onClosebj} style={{cursor:'pointer'}}>
                <Icon type="arrow-left" style={{ marginRight: 20 }} />
                添加/编辑词槽
              </span>
            }
            placement="right"
            closable={false}
            onClose={this.onClosebj}
            visible={this.state.addModel}
            width="calc(100vw - 245px)"
            destroyOnClose
          >
            <div className={styles.der}>
              <Form className="zdyfroma" layout="horizontal">
                <FormItem
                  label={<FormattedMessage id="app.wordTroughManage.word-name" />}
                  className={styles.wardfrom}
                >
                  {getFieldDecorator('wordName', {
                    initialValue: `${this.state.wordName}`,
                    rules: [
                      { required: true, message: '实体名称不能为空！' },
                      { pattern: /^[a-z0-9\._]*$/g, message: '仅限填写小写字母、数字或下划线' },
                    ],
                  })(<Input placeholder="仅限填写小写字母、数字或下划线" />)}
                </FormItem>
                <FormItem
                  label={<FormattedMessage id="app.wordTroughManage.word-alias" />}
                  className={styles.wardfrom}
                >
                  {getFieldDecorator('wordAlias', {
                    initialValue: `${this.state.wordAlias}`,
                    rules: [{ required: true, message: '词槽别名不能为空！' }],
                  })(<Input placeholder="方便记忆和区分词槽，建议使用中文" />)}
                </FormItem>
                <FormItem
                  label={<FormattedMessage id="app.wordTroughManage.corresponding-dictionary" />}
                  className={styles.wardfrom}
                  {...FormItemLayont}
                >
                  <div>
                    {this.state.editor === true ? (
                      <Button style={{ marginRight: 5 }} size="small" onClick={this.newModal}>
                        添加
                      </Button>
                    ) : (
                      <span>
                        {' '}
                        <span style={{ marginRight: 12 }}>{this.state.textOne}</span>
                        {this.state.isEnumTwo ? (
                          <Button onClick={this.message} style={{ marginRight: 5 }} size="small">
                            编辑
                          </Button>
                        ) : null}
                      </span>
                    )}
                    <Button onClick={this.newModal} size="small">
                      更换
                    </Button>
                  </div>
                </FormItem>
                <FormItem label="询问话术" className={styles.wardfrom}>
                  {getFieldDecorator('visitWords', {
                    initialValue: `${this.state.visitWords}`,
                    rules: [{ required: true, message: '询问话术不能为空' }],
                  })(<Input placeholder="当前词槽为空时询问用户的话术" />)}
                </FormItem>
                <FormItem label="附加选项" className={styles.wardfrom} {...FormItemLayont}>
                  <RadioGroup onChange={this.onChange} value={this.state.value}>
                    <Radio value={'none'}>
                      <FormattedMessage id="app.wordTroughManage.automatic" />
                    </Radio>
                    <Radio value={'user'}>
                      <FormattedMessage id="app.wordTroughManage.value-options" />
                    </Radio>
                  </RadioGroup>
                </FormItem>
                {this.state.value === 'none'
                  ? ''
                  : this.state.choice.map((item, index) => {
                      return (
                        <div className={styles.maginrht}>
                          <Form layout="inline" style={{ marginBottom: 10 }}>
                            <FormItem>
                              <Input
                                style={{ width: 130 }}
                                value={item.customs[0]}
                                onChange={e => this.busChange(e, index)}
                              />
                            </FormItem>
                            <FormItem>
                              {/* <span><MyIcon type="icon-lajixiang" onClick={() => this.handleSubmitA(index)} /></span> */}
                              {// item.plug === 'tcx' ? <Button onClick={() => this.handleSubmitA(index)}>添加</Button> : <MyIcon type="icon-lajixiang" onClick={() => this.handleSubmitAs(index)} />
                              item.plug === 'tcx' ? (
                                <Button onClick={() => this.handleSubmitA(index)}>添加</Button>
                              ) : (
                                <img src={ljx} onClick={() => this.handleSubmitAs(index)} />
                              )}
                            </FormItem>
                          </Form>
                        </div>
                      );
                    })}
              </Form>
              <div className={styles.flex}>
                <div>
                  {/*<img onClick={this.onClosebj} src={qxbuttom} style={{ marginRight: 50 }} />*/}
                  <img onClick={this.operation} src={qdbuttom} />
                </div>
              </div>
            </div>
          </Drawer>
          {/* <Modal
            className="modelZdy"
            title={<FormattedMessage id="app.wordTroughManage.add-edit-slots" />}
            visible={this.state.addModel}
            okText={<FormattedMessage id="app.wordTroughManage.save" />}
            cancelText={<FormattedMessage id="app.wordTroughManage.cancel" />}
            onCancel={() => {
              this.setState({
                addModel: false,
                editor: true,
                onChantTable: 1,
              });
              this.beginFrom();
            }}
            onOk={this.operation}
          >

          </Modal> */}
          <Drawer
            className="zdyset"
            title={
              <span>
                <Icon type="arrow-left" style={{ marginRight: 20 }} />
                添加实体
              </span>
            }
            placement="right"
            closable
            onClose={() => {
              this.setState({
                showModel: false,
                onChantTable: 1,
              });
            }}
            visible={this.state.showModel}
            width="calc(100vw - 245px)"
            destroyOnClose
          >
            <div className={styles.der}>
              {/* <div className={styles.overall}> */}
              <Form className="zdyfroma" layout="horizontal">
                <FormItem label="实体类型" className={styles.wardfrom} {...FormItemLayont}>
                  <RadioGroup onChange={this.onChantTable} value={this.state.onChantTable}>
                    <Radio value={1}>个性化实体</Radio>
                    <Radio value={2}>系统实体</Radio>
                  </RadioGroup>
                </FormItem>
              </Form>
              <span style={{ marginBottom: 20 }}>
                {getFieldDecorator('seektk', {
                  initialValue: '',
                })(
                  <Search
                    // allowClear
                    placeholder="请输入搜索内容"
                    onSearch={value => {
                      if (this.state.dictType === 'sys') {
                        this.setState({ inputT: value }, () => {
                          this.fetchd();
                        });
                      } else {
                        this.setState({ inputT: value }, () => {
                          this.fetche();
                        });
                      }
                    }}
                    style={{ width: 322, paddingLeft: 24 }}
                  />
                )}
              </span>
              <span style={{ marginLeft: 18 }}>
                <Button onClick={this.addDictionary} type="primary">
                  添加实体
                </Button>
              </span>
              <div style={{ height: 10 }} />
              <div>
                <Spin spinning={this.state.login}>
                  {/* <div className={styles.ovller}> */}
                  <div className={styles.overall} style={{ padding: '0px 20px' }}>
                    <div className={styles.border} style={{ padding: '0px 0px 1px 1px' }}>
                      <Table
                        className="zdyTable"
                        // style={{ padding: '20px 0px 0px 0px' }}
                        columns={this.bardian}
                        dataSource={this.state.personalityList} //数据
                        pagination={false} //分页设置
                      />
                    </div>
                  </div>
                </Spin>
                {this.state.dictType === 'sys' ? null : (
                  <Pagination
                    className={styles.floatA}
                    pageSize={this.state.pageSizeC}
                    current={this.state.pageC}
                    total={this.state.personalitytotalC}
                    showSizeChanger={true}
                    onChange={this.onChangeC}
                    onShowSizeChange={this.onShowSizeChangeC}
                  />
                )}
              </div>

              {/* </div> */}
            </div>
          </Drawer>
          {/* <Modal
            width={900}
            className="modelZdy"
            title="选择实体"
            visible={this.state.showModel}
            footer={null}
            okText="保存"
            cancelText="取消"
            onCancel={() => {
              this.setState({
                showModel: false,
                onChantTable: 1,
              });
            }}
            // onOk={this.operation}
          >

          </Modal> */}
          <Drawer
            title="词槽使用情况"
            placement="right"
            closable
            onClose={this.onClose}
            visible={this.state.close}
            width={800}
            destroyOnClose
          >
            <Service item={this.state.item} />
          </Drawer>
          {/* </Card> */}
        </div>
        <RobotBtn />
      </div>
    );
  }

  newWordTrough = () => {
    this.setState({
      addModel: true,
      editor: true,
      wordName: '',
      wordAlias: '',
      visitWords: '',
      choice: [{ choiceType: 'user', customs: [], plug: 'tcx' }],
      value: 'none',
    });
    this.beginFrom();
  };

  operation = () => {
    if (!this.state.editor) {
      // 判断对应词典是否为空
      let userInfo = this.props.form.getFieldsValue();
      this.props.form.validateFields((err, values) => {
        if (!err) {
          console.log(userInfo);
          let arr = this.state.choice;
          let ayy = {};
          let att = [];
          arr.map((item, index) => {
            att.push(item.customs.join());
          });
          console.log(this.state.value);
          if (this.state.value === 'none') {
            // 自动
            delete ayy.choiceType;
            delete ayy.plug;
            ayy.choiceType = 'none';
            ayy.customs = [];
            console.log(ayy);
            console.log(arr, this.state.onChantwobr);
            const { dispatch, currentUser } = this.props;
            this.setState({ value: 'none' });
            this.reqRef = requestAnimationFrame(() => {
              dispatch({
                type: 'wordTroughManage/fetchb',
                payload: {
                  firstDictId: this.state.textId,
                  key: userInfo.wordName,
                  name: userInfo.wordAlias,
                  secondDictId: '',
                  inquire: userInfo.visitWords,
                  choice: ayy,
                  slotId: this.state.slotId,
                },
                callback: res => {
                  console.log('新增词槽', res);
                  if (res.code) {
                  } else {
                    this.setState({
                      value: 'none',
                      addModel: false,
                      slotId: '',
                      wordName: '',
                      wordAlias: '',
                      visitWords: '',
                      editor: true,
                      choice: [{ choiceType: 'user', customs: [], plug: 'tcx' }],
                    });
                    this.beginFrom();
                    message.success('执行成功！');
                  }
                  this.fetch(this.state.yeshua, this.state.yeshub, this.state.zhuvalue);
                  this.setState({ value: 'none', onChantTable: 1 });
                },
              });
            });
          } else {
            // 自定义
            // eslint-disable-next-line no-lonely-if
            if (att[0] == '') {
              ayy.choiceType = 'none';
              ayy.customs = att;
              console.log(ayy);
              message.error('附加选项 -> 自定义选项为空！');
            } else {
              ayy.choiceType = 'user';
              ayy.customs = att;
              console.log(ayy);
              let listData = [];
              ayy.customs.map(item => {
                if (item.length !== 0) {
                  listData.push(item);
                }
              });
              ayy.customs = listData;
              const { dispatch, currentUser } = this.props;

              this.reqRef = requestAnimationFrame(() => {
                dispatch({
                  type: 'wordTroughManage/fetchb',
                  payload: {
                    firstDictId: this.state.textId,
                    key: userInfo.wordName,
                    name: userInfo.wordAlias,
                    secondDictId: '',
                    inquire: userInfo.visitWords,
                    choice: ayy,
                    slotId: this.state.slotId,
                  },
                  callback: res => {
                    console.log('新增词槽', res);
                    if (res.code) {
                    } else {
                      this.setState({
                        addModel: false,
                        wordName: '',
                        wordAlias: '',
                        visitWords: '',
                        editor: true,
                        choice: [{ choiceType: 'user', customs: [], plug: 'tcx' }],
                      });
                      this.beginFrom();
                      message.success('执行成功！');
                    }
                    this.fetch(this.state.yeshua, this.state.yeshub, this.state.zhuvalue);
                    this.setState({ value: 'none', onChantTable: 1 });
                  },
                });
              });
            }
          }
        }
      });
    } else {
      message.error('请添加对应实体后再保存');
    }
  };

  newModal = () => {
    this.setState({ showModel: true });
    this.fetche();
  };

  onChange = e => {
    console.log('radio checked', e.target.value);
    this.setState({ value: e.target.value });
  };

  busChangetwo = e => {
    console.log(e.target.value);
  };

  onChantTable = e => {
    console.log('radio checked', e.target.value);

    if (e.target.value === 2) {
      this.props.form.setFields({ seektk: '' });
      this.setState({
        dictType: 'sys',
        page: 1,
        pageSize: 10,
        inputT: '',
      });
      this.fetchd();
    }
    if (e.target.value === 1) {
      this.props.form.setFields({ seektk: '' });
      this.setState({
        dictType: 'user',
        pageC: 1,
        pageSizC: 10,
        inputT: '',
      });
      this.fetche();
    }
    this.setState({
      onChantTable: e.target.value,
    });
  };

  onChangeA = a => {
    console.log(a, this.state.dictType);
    this.setState({
      page: a,
    });
    this.fetchd(this.state.dictType, a, '', '');
  };

  onShowSizeChangeA = (a, b) => {
    console.log(a, b);
    this.fetchd(this.state.dictType, a, b, '');
    this.setState({
      page: a,
      pageSize: b,
    });
  };

  onChangeC = a => {
    console.log(a);
    this.setState(
      {
        pageC: a,
      },
      () => {
        this.fetche();
      }
    );
  };

  onShowSizeChangeC = (a, b) => {
    console.log(a, b);
    this.setState(
      {
        pageC: a,
        pageSizeC: b,
      },
      () => [this.fetche()]
    );
  };

  addDictionary = () => {
    const { textId, textOne, isEnum } = this.state;
    const w = window.open('about:blank');
    if (isEnum) {
      w.location.href = `/basic/customDictionary/enumerable?${textId}&${textOne}`;
      this.setState({ addModel: false });
    } else {
      w.location.href = `/basic/customDictionary/noEnumerationNew?${textId}&${textOne}`;
      this.setState({ addModel: false });
    }
  };

  message = () => {
    console.log('22');
    const { textId, textOne, isEnum } = this.state;
    const w = window.open('about:blank');
    if (isEnum) {
      w.location.href = `/basic/customDictionary/enumerable?${textId}&${textOne}`;
      this.setState({ addModel: false });
    } else {
      w.location.href = `/basic/customDictionary/noEnumerationNew?${textId}&${textOne}`;
      this.setState({ addModel: false });
    }
  };

  handleSubmitA = index => {
    console.log(index);
    let arr = this.state.choice;
    let dictItems = {
      wchoiceType: this.state.value,
      customs: [],
      plug: 'tcx',
    };
    arr.push(dictItems);
    console.log(arr);
    this.setState({
      choice: arr,
    });
    if (index > 0) {
      arr[index].plug = '';
    }
    arr[index].plug = '';
  };

  //删除
  handleSubmitAs = index => {
    console.log(index);
    let arr = this.state.choice;
    arr.splice(index, 1);
    console.log(arr);
    this.setState({
      choice: arr,
    });
    this.props.form.resetFields();
    console.log(index);
  };

  handleDeletes = val => {
    console.log(val);
    let text;
    if (val.inUse) {
      Modal['confirm']({
        title: '删除任务',
        content: '该词槽正在被使用中，删除后将影响机器人的正常问答，是否确定删除',
        okText: '删除',
        cancelText: '取消',
        onOk: () => {
          const { dispatch } = this.props;
          this.reqRef = requestAnimationFrame(() => {
            dispatch({
              type: 'wordTroughManage/fetchc',
              payload: { id: val._id },
              callback: res => {
                console.log('列表数据', res);
                if (res.code === 0) {
                  message['success'](`${res.msg}`);
                  this.fetch(this.state.yeshua, this.state.yeshub, this.state.zhuvalue);
                } else {
                  message['error'](`${res.msg}`);
                }
              },
            });
          });
        },
        onCancel() {
          console.log('onCancel');
        },
      });
    } else {
      Modal['confirm']({
        title: '删除任务',
        content: '是否确定删除该词槽',
        okText: '删除',
        cancelText: '取消',
        onOk: () => {
          const { dispatch } = this.props;
          this.reqRef = requestAnimationFrame(() => {
            dispatch({
              type: 'wordTroughManage/fetchc',
              payload: { id: val._id },
              callback: res => {
                console.log('列表数据', res);
                if (res.code === 0) {
                  message['success'](`${res.msg}`);
                  this.fetch(this.state.yeshua, this.state.yeshub, this.state.zhuvalue);
                } else {
                  message['error'](`${res.msg}`);
                }
              },
            });
          });
        },
        onCancel() {
          console.log('onCancel');
        },
      });
    }
  };

  busChange = (e, index) => {
    console.log(e.target.value, index);
    let arr = this.state.choice;
    arr[index].customs = [];
    arr[index].customs.push(e.target.value);
    this.setState({
      choice: arr,
      choiceType: 'user',
    });
    console.log(this.state.choice);
  };
}

export default connect(({ user }) => ({
  // 全局数据
  currentUser: user.currentUser,
}))(Form.create()(WordTroughManage));
